package com.bjtu.literatureclient.dao.city;

import com.bjtu.literatureclient.domain.base.BaseModel;
import com.bjtu.literatureclient.domain.city.CityState;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
public interface ICityStateDao {
    /*@Select("<script>SELECT  * FROM citystatetable WHERE 1=1\n" +
            "<if test=\"cityID!=null and cityID!=''\">\n" +
            "AND CityID=#{cityID}\n" +
            "</if>\n" +
            "<if test=\"region!=null and region!=''\">\n" +
            "AND Region=#{region}\n" +
            "</if>\n" +
            "<if test=\"stateName2!=null and stateName2!=''\">\n" +
            "AND StateName2=#{stateName2}\n" +
            "</if>\n" +
            "<if test=\"stateName1!=null and stateName1!=''\">\n" +
            "AND StateName1=#{stateName1}\n" +
            "</if>\n" +
            "<if test=\"stateAbbr!=null and stateAbbr!=''\">\n" +
            "AND StateAbbr=#{stateAbbr}\n" +
            "</if>\n" +
            "<if test=\"cityName2!=null and cityName2!=''\">\n" +
            "AND CityName2=#{cityName2}\n" +
            "</if>\n" +
            "<if test=\"cityName1!=null and cityName1!=''\">\n" +
            "AND CityName1=#{cityName1}\n" +
            "</if>\n" +
            "<if test=\"dateTime!=null and dateTime!=''\">\n" +
            "AND DateTime=#{dateTime}\n" +
            "</if>\n" +
            "<if test=\"ifuse!=null and ifuse!=''\">\n" +
            " AND IFUSE=#{ifuse}\n" +
            "</if>" +
            "</script>")*/
    List<CityState> query(BaseModel baseModel);

    @Insert("<script>" +
            " INSERT INTO citystatetable (Region,StateName2,StateName1, StateAbbr,CityName2,CityName1," +
            " DateTime,IfUse)" +
            " VALUES (#{region},#{stateName2},#{stateName1},#{stateAbbr},#{cityName2},#{cityName1}," +
            " #{dateTime},#{ifuse})" +
            "</script>")
    int insert(BaseModel baseModel);

    @Update("<script>" +
            "UPDATE citystatetable\n" +
            " <trim prefix=\"SET\" suffixOverrides=\",\">\n" +
            "<if test=\"region!=null and region!=''\">\n" +
            " Region=#{region},\n" +
            "</if>\n" +
            "<if test=\"stateName2!=null and stateName2!=''\">\n" +
            " StateName2=#{stateName2},\n" +
            "</if>\n" +
            "<if test=\"stateName1!=null and stateName1!=''\">\n" +
            " StateName1=#{stateName1},\n" +
            "</if>\n" +
            "<if test=\"stateAbbr!=null and stateAbbr!=''\">\n" +
            " StateAbbr=#{stateAbbr},\n" +
            "</if>\n" +
            "<if test=\"cityName1!=null and cityName1!=''\">\n" +
            " CityName1=#{cityName1},\n" +
            "</if>\n" +
            "<if test=\"dateTime!=null and dateTime!=''\">\n" +
            " DateTime=#{dateTime},\n" +
            "</if>\n" +
            "<if test=\"ifuse!=null and ifuse!=''\">\n" +
            " IfUse=#{ifuse}\n" +
            "</if>" +
            " </trim>" +
            "WHERE CityID=#{cityID}" +
            "</script>")
    int update(BaseModel baseModel);
    
    @Select("<script>SELECT  DISTINCT StateName2 FROM citystatetable WHERE 1=1\n" +
            "<if test=\"region!=null and region!=''\">\n" +
            "AND Region=#{region}\n" +
            "</if>"  +
            "</script>")
    List<CityState> queryState(BaseModel baseModel);
    
    @Select("<script>SELECT  DISTINCT CityName2,CityName1 FROM citystatetable WHERE 1=1\n" +
    		 "<if test=\"stateName2!=null and stateName2!=''\">\n" +
             " AND StateName2=#{stateName2}\n" +
             "</if>\n" +
            "<if test=\"region!=null and region!=''\">\n" +
            "AND Region=#{region}\n" +
            "</if>"  +
            "</script>")
    List<CityState> queryCity(BaseModel baseModel);

}
